** Revised Table 1: all summary statistics


* Label variables as you want them in the table

	label var male "Male"
	label var white "White"
	label var black "Black"
	label var hisp "Hispanic"
	label var othrace "Other Race"
	label var lep_dv "English Language Learner"
	label var sped_dv "Special Education"
	label var frpl_dv "Receiving Free and Reduced-Price Lunch"
	
	foreach var of varlist nothreat_cycle3 experience pos_ntc3 {
	    local label_`var' : variable label `var'
	}
	
	label var experience "Average Years of Experience (std. dev.)"
	label var pos_ntc3 "Has Unmonitored Time"
	label var nothreat_cycle3 "Average Days Unmonitored if Unmonitored (std. dev.)"

	cap: label define _mygrades 1 "4th Grade" 2 "5th Grade" 3 "6th Grade"
	label values grade_c _mygrades
	
	cap: label define _mygender 0 "Female" 1 "Male"
	label values male _mygender
	
	cap: label define _dummy_lab 0 "No" 1 "Yes"
	label values  lep_dv _dummy_lab
	label values sped_dv _dummy_lab
	label values frpl_dv _dummy_lab
	label values pos_ntc3 _dummy_lab
	
	label var year "Year"
	
	
	
** CREATE TABLE (COLLECTION)
collect clear
			
	* STUDENTS

		preserve

			
			duplicates drop stu_id year, force

			g race = .
			replace race = 3 if white
			replace race = 1 if black
			replace race = 2 if hisp
			replace race = 4 if othrace
			
			label var race "Race"
			
			label define _mystudrace 1 "Black" 2 "Hispanic" 3 "White" 4 "Other" 
			label values race _mystudrace
			
			
			g n_student = 1
			label var n_student "Students"	
		
			global mydumbvars grade_c male race lep_dv sped_dv frpl_dv
			
			collect clear
			collect: table (var) (year), stat(sum n_student) stat(fvfrequency $mydumbvars) stat(fvpercent $mydumbvars) name(t1)
		
		restore	
		
	* TEACHERS
			
		preserve
		
			duplicates drop id year, force
			gen n_teacher = 1
			label var n_teacher "Teachers"
			collect: table (var) (year), stat(sum n_teacher) stat(mean experience) stat(sd experience) ///
				stat(fvfrequency pos_ntc3) stat(fvpercent pos_ntc3) name(t1) append
			collect: table (var) (year) if nothreat_cycle3>0, stat(mean nothreat_cycle3) ///
				stat(sd nothreat_cycle3) name(t1) append
				
		restore
	
	
	
** TABLE MADE, NOW JUST FORMAT **

	* put the frequencies and sd to the right
	collect remap result[total] = result[fvfrequency]
	collect remap result[mean] = result[fvfrequency]
	collect remap result[sd] = result[fvpercent]

	* format cells
		* percents
		collect style cell colname[${mydumbvars} trace pos_ntc3]#result[fvpercent], nformat(%6.1f) sformat("%s%%")
		
		* counts
		collect style cell colname[${mydumbvars} trace pos_ntc3]#result[fvfrequency], nformat(%6.0fc)
				
		* SD --> note that now it is tagged as fvpercent!
		collect style cell colname[experience nothreat_cycle3]#result[fvpercent], nformat(%6.2f) sformat("(%s)")
	
		* MEAN -- > note that now it is tagged as fvfrequency
		collect style cell colname[experience nothreat_cycle3]#result[fvfrequency], nformat(%6.2f)
	
	
	collect style use table-1
	collect style header result, level(hide)
	collect style row stack, nodelimiter spacer
	
	
	collect style cell colname[n_student], border(bottom)
	collect style cell colname[n_teacher], border(bottom)
	
	** THIS WAS CHANGED TO DROP YEARS. year[.m] can be changed to just year to put them back in
	
	collect layout (colname) (year[.m]#result[fvfrequency fvpercent])
	
	
	
	* fix borders
	collect style cell border_block, border(left, pattern(nil))
	collect style cell border_block, border(right, pattern(nil))
	
	collect preview
	
	
	
** export to latex
	collect export "$output_dir\Tables\_Table_01.tex", replace tableonly
	
	
	*** RESTORE THE LABELS
	foreach var of varlist nothreat_cycle3 experience pos_ntc3 {
	    label var `var' "`label_`var''"
	}
	
	
